package org.umlviewer.model.diagram_class;

import org.umlviewer.model.Constants;
import org.umlviewer.model.VisibilityKind;
import org.jdom2.Element;
import org.jdom2.Namespace;

/**
 *
 * @author Rafa
 */
public class Attribute extends TypedElement {


    private VisibilityKind visibility;
    private boolean bstatic;    

    public Attribute() {
        super();
        setName("");
        bstatic = false;
        visibility = VisibilityKind.V_PUBLIC;        
    }

    public Attribute(String name, String type, VisibilityKind visibility) {
        super(type);
        setName(name);
        this.visibility = visibility;
        bstatic = false;        
    }        

    public VisibilityKind getVisibility() {
        return visibility;
    }

    public void setVisibility(VisibilityKind visibility) {
        this.visibility = visibility;
    }
    
    public boolean isStatic(){
        return this.bstatic;
    }
    
    public void setStatic(boolean s){
        this.bstatic = s;
    }

    public void xmiSerialize(Element parent) {
        Namespace xmins = Constants.XMINAMESPACE;
        Element att = new Element("ownedAttribute");
        att.setAttribute("type","uml:Property",xmins);
        att.setAttribute("id",getId(),xmins);
        att.setAttribute("name",getName());
        att.setAttribute("visibility",visibility.toString());
        if(isStatic())
            att.setAttribute("isStatic","true");
        //definir estos atributos en la clase
        att.setAttribute("isDerived","false");
        att.setAttribute("isOrdered","false");
        att.setAttribute("isUnique","false");
        att.addContent(new Element("type").setAttribute("idref",getType(),xmins)); //tipo del atributo
        
        parent.addContent(att);        
    }
    
}
